/**
 * Created by hezhijie on 2016/11/22.
 */
var app = angular.module("app", [
    "ui.router",    //路由
    "oc.lazyLoad",  //延迟加载
    "ngCookies", 'ui.bootstrap'
]);


/*
 * 加载配置,配置路由
 * 路由配置方式
 * $stateProvider.state("state", {})
 * 其中"state"为路由状态，为一个页面设置一个状态，不设置重复状态。
 *
 * {},路由参数
 * 常用参数
 * url : 页面跳转后url，配置后可在浏览器上看到。浏览器输入对应地址也可访问到
 * templateUrl : 模版/页面路径
 * template : 模版内容，可为html代码
 * views : 多视图配置，key对应ui-view="name"。不配置将加载<div ui-view></div>中
 * 深入了解可详见http://bubkoo.com/2014/01/01/angular/ui-router/guide/multiple-named-views/
 * resolve :
 *
 *
 *
 * ["$stateProvider", "$urlRouterProvider", function($a, $b){}]  DI，自动注入。修改配置方式，用于代码压缩时方便
 */
app.config(["$stateProvider", "$urlRouterProvider", function ($state, $urlRouter) {

    $urlRouter.otherwise('/login');

    $state.state("login", {
        url: '/login',
        templateUrl: basePath + '/modules/login/login.html',
        resolve: {
            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                return $ocLazyLoad.load([
                    "lib/metronic/assets/admin/pages/css/login-soft.css",
                    "lib/metronic/assets/admin/pages/scripts/login-soft.js",
                    "modules/login/js/login.js",
                ]);
            }]
        }
    })

    $state.state("payPage", {
        url: '/payPage/:merchantId',
        templateUrl: basePath + '/modules/order/payPage.html',
        resolve: {
            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                return $ocLazyLoad.load([
                    "modules/order/js/payPage.js"
                ]);
            }]
        }
    })

    $state.state('home', {
        url: "/home",
        templateUrl: basePath + '/modules/home/home.html',
        controller: function () {
            Metronic.init();
        },
        resolve: {
            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                return $ocLazyLoad.load([
                    "lib/metronic/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js",
                    "lib/metronic/assets/admin/layout/scripts/quick-sidebar.js",
                    "lib/metronic/assets/admin/pages/scripts/index.js",
                    "lib/metronic/assets/admin/pages/scripts/tasks.js",
                ]);
            }]
        }
    })
    $state.state('home.content', {
        url: '/content',
        views: {
            "header": {
                templateUrl: basePath + '/modules/home/header.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            "modules/home/js/header.js",
                        ]);
                    }]
                }
            },
            "sidebar": {
                templateUrl: basePath + '/modules/home/sidebar.html',
                controller: function () {
                    Layout.initSidebar();
                }
            },
            "footer": {
                templateUrl: basePath + '/modules/home/footer.html',
                controller: function () {
                    Layout.initFooter();
                }
            },
            "content": {
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            "modules/home/js/home.js",
                        ]);
                    }]
                }
            }
        }
    });
    $state.state('home.content.detectLog', {
        url: '/detectLog'
    });
    $state.state('home.content.detectLog.statistic', {
        url: '/statistic',
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/detectLog/statistic.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/lib/bootstrap-datetimepicker-2.3.8/css/bootstrap-datetimepicker.min.css",
                            basePath + "/lib/bootstrap-datetimepicker-2.3.8/js/bootstrap-datetimepicker.min.js",
                            basePath + "/lib/chart/echarts-all.js",
                            "modules/detectLog/js/statistic.js",
                        ]);
                    }]
                }
            }
        }
    });

    $state.state("home.content.detectLog.machineStatisticList", {
        url: "/machineStatisticList?deptName&queryPeriod",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/detectLog/machineStatisticList.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/lib/bootstrap-datetimepicker-2.3.8/css/bootstrap-datetimepicker.min.css",
                            basePath + "/lib/bootstrap-datetimepicker-2.3.8/js/bootstrap-datetimepicker.min.js",
                            basePath + "/modules/detectLog/js/machineStatisticList.js"
                        ]);
                    }]
                }
            }
        }
    });
    $state.state("home.content.detectLog.machineStatisticDetail", {
        url: "/machineStatisticDetail?id",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/detectLog/machineStatisticDetail.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/modules/detectLog/css/machineStatisticDetail.css",
                            basePath + "/modules/detectLog/js/machineStatisticDetail.js"
                        ]);
                    }]
                }
            }
        }
    });
    $state.state("home.content.detectLog.detectLogList", {
        url: "/detectLogList?machineCode&queryPeriod",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/detectLog/detectLogList.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/lib/bootstrap-datetimepicker-2.3.8/css/bootstrap-datetimepicker.min.css",
                            basePath + "/lib/bootstrap-datetimepicker-2.3.8/js/bootstrap-datetimepicker.min.js",
                            basePath + "/modules/detectLog/js/detectLogList.js"
                        ]);
                    }]
                }
            }
        }
    });
    $state.state("home.content.detectLog.detectLogDetail", {
        url: "/detectLogDetail?id",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/detectLog/detectLogDetail.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/modules/detectLog/css/detectLogDetail.css",
                            basePath + "/modules/detectLog/js/detectLogDetail.js"
                        ]);
                    }]
                }
            }
        }
    });

    $state.state('home.content.appVersion', {
        url: '/appVersion'
    });
    $state.state("home.content.appVersion.list", {
        url: "/list",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/app/appList.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/modules/app/js/appList.js"
                        ]);
                    }]
                }
            }
        }
    });

    $state.state('home.content.order', {
        url: '/order'
    });
    $state.state("home.content.order.orderList", {
        url: "/orderList",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/order/orderList.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/modules/order/js/orderList.js"
                        ]);
                    }]
                }
            }
        }
    });
    $state.state("home.content.order.orderDetail", {
        url: "/orderDetail?id",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/order/orderDetail.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/modules/order/js/orderDetail.js"
                        ]);
                    }]
                }
            }
        }
    });


    $state.state('home.content.merchant', {
        url: '/merchant'
    });
    $state.state("home.content.merchant.merchantList", {
        url: "/merchantList",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/merchant/merchantList.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/modules/merchant/js/merchantList.js"
                        ]);
                    }]
                }
            }
        }
    });
    $state.state("home.content.merchant.merchantDetail", {
        url: "/merchantDetail?id",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/merchant/merchantDetail.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/modules/merchant/js/merchantDetail.js"
                        ]);
                    }]
                }
            }
        }
    });

    $state.state('home.content.agent', {
        url: '/agent'
    });
    $state.state("home.content.agent.agentList", {
        url: "/agentList",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/agent/agentList.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/lib/ztree/3.5/zTreeStyle.css",
                            basePath + "/lib/ztree/3.5/jquery.ztree.all-3.5.min.js",
                            basePath + "/modules/agent/js/agentList.js"
                        ]);
                    }]
                }
            }
        }
    });
    $state.state("home.content.agent.agentDetail", {
        url: "/agentDetail?id",
        views: {
            "content@home": {
                templateUrl: basePath + '/modules/agent/agentDetail.html',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            basePath + "/modules/agent/js/agentDetail.js"
                        ]);
                    }]
                }
            }
        }
    });
}]);


app.controller("AppCtrl", ['$scope',
    function ($scope) {
        $scope.transference=transference;
        $scope.transformBool = function (val) {
            if (val == true || 'true' == val) {
                return "是"
            } else {
                return "否"
            }
        }
    }]);

/**
 * app启动后执行，常用于配置全局变量
 */
app.run([
    "$rootScope",
    "$state",
    "$stateParams",
    "$location",
    "$cookieStore",
    function ($rootScope, $state, $stateParams, $location, $cookieStore) {
        global.$rootScope=$rootScope;
        $rootScope.basePath = basePath;
        $rootScope.$rootScope = $rootScope;
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $rootScope.$location = $location;
        $rootScope.$cookieStore = $cookieStore;
        $rootScope.back = function () {
            history.back();
        }
    }
]);